﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YBApproval.IDAL;
using YBApproval.Model;
using System.Data.Entity;
using System.Data;

namespace YBApproval.EFDAL
{
    public class ProcessDAL: IProcess
    {
        private YBDbContext _db = new YBDbContext();

        public Process GetProcess(int formId)
        {
            try
            {
                Process process = _db.Processes.SingleOrDefault(p => p.Id == formId);
                return process;
            }
            catch (Exception)
            {
                return null;
            }
        }

        public IList<Form_ProcessSet> GetAllProcesses()
        {
            try
            {
                IQueryable<Form_ProcessSet> formProcess = (from fp in _db.Form_ProcessSets
                                                           where fp.IsActive
                                                           select fp).Include(fp => fp.Form).Include(fp=>fp.Process);
                return formProcess.ToList();
            }
            catch (Exception)
            {
                return null;
            }
        }
        public void Dispose()
        {
            _db.Dispose();
        }

    }
}
